package com.woniuxy.dto;

import com.woniuxy.entity.CustomerBasicInfo;
import com.woniuxy.entity.CustomerDeliveryInfo;
import com.woniuxy.entity.CustomerInvoiceInfo;
import com.woniuxy.entity.CustomerOrderUnitInfo;
import lombok.Data;

import java.util.Date;

/**
 * 客户详情DTO
 */
@Data
public class CustomerDetailDto {
    
    // 基本信息
    private Long id;
    private String customerName;
    private String contactPerson;
    private String phone;
    private String email;
    private String industry;
    private String remarks;
    private String approvalStatus;
    private String processInstanceId;
    private String customerCode;
    private Date createdAt;
    private Date updatedAt;
    private String currentStep;
    private String currentApprover;
    private String rejectReason;
    private String rejectStep;
    private String createBy;
    private String updateBy;
    
    // 收货信息
    private String deliveryName;
    private String deliveryPhone;
    private String deliveryAddress;
    private String province;
    private String city;
    private String district;
    
    // 开票信息
    private String invoiceTitle;
    private String taxNumber;
    private String bankName;
    private String bankAccount;
    
    // 订货单位信息
    private String orderUnitName;
    private String address;
    private String orderContactPerson;
    private String orderPhone;
    
    /**
     * 从实体类构建DTO
     */
    public static CustomerDetailDto fromEntities(CustomerBasicInfo basicInfo, 
                                                CustomerDeliveryInfo deliveryInfo,
                                                CustomerInvoiceInfo invoiceInfo,
                                                CustomerOrderUnitInfo orderUnitInfo) {
        CustomerDetailDto dto = new CustomerDetailDto();
        
        // 基本信息
        if (basicInfo != null) {
            dto.setId(basicInfo.getId());
            dto.setCustomerName(basicInfo.getCustomerName());
            dto.setContactPerson(basicInfo.getContactPerson());
            dto.setPhone(basicInfo.getPhone());
            dto.setEmail(basicInfo.getEmail());
            dto.setIndustry(basicInfo.getIndustry());
            dto.setRemarks(basicInfo.getRemarks());
            dto.setApprovalStatus(basicInfo.getApprovalStatus());
            dto.setProcessInstanceId(basicInfo.getProcessInstanceId());
            dto.setCustomerCode(basicInfo.getCustomerCode());
            dto.setCreatedAt(basicInfo.getCreatedAt());
            dto.setUpdatedAt(basicInfo.getUpdatedAt());
            dto.setCurrentStep(basicInfo.getCurrentStep());
            dto.setCurrentApprover(basicInfo.getCurrentApprover());
            dto.setRejectReason(basicInfo.getRejectReason());
            dto.setRejectStep(basicInfo.getRejectStep());
            dto.setCreateBy(basicInfo.getCreateBy());
            dto.setUpdateBy(basicInfo.getUpdateBy());
        }
        
        // 收货信息
        if (deliveryInfo != null) {
            dto.setDeliveryName(deliveryInfo.getDeliveryName());
            dto.setDeliveryPhone(deliveryInfo.getDeliveryPhone());
            dto.setDeliveryAddress(deliveryInfo.getDeliveryAddress());
            dto.setProvince(deliveryInfo.getProvince());
            dto.setCity(deliveryInfo.getCity());
            dto.setDistrict(deliveryInfo.getDistrict());
        }
        
        // 开票信息
        if (invoiceInfo != null) {
            dto.setInvoiceTitle(invoiceInfo.getInvoiceTitle());
            dto.setTaxNumber(invoiceInfo.getTaxNumber());
            dto.setBankName(invoiceInfo.getBankName());
            dto.setBankAccount(invoiceInfo.getBankAccount());
        }
        
        // 订货单位信息
        if (orderUnitInfo != null) {
            dto.setOrderUnitName(orderUnitInfo.getOrderUnitName());
            dto.setAddress(orderUnitInfo.getAddress());
            dto.setOrderContactPerson(orderUnitInfo.getContactPerson());
            dto.setOrderPhone(orderUnitInfo.getPhone());
        }
        
        return dto;
    }
}
